package com.sylar.lelepub;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;

import com.sylar.lelepub.adapter.NearPubAdapter;
import com.sylar.lelepub.widget.XListView;
import com.sylar.lelepub.widget.XListView.IXListViewListener;

public class NearListActivity extends Activity implements IXListViewListener, OnItemClickListener, OnClickListener {
	private ArrayList<String> items = new ArrayList<String>();
	private XListView near_listView;
	private NearPubAdapter nearPubAdapter;
	private int start = 0;
	private Button mapbtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.layout_near_pub);

		geneItems();

		findView();

		setData();
	}

	private void geneItems() {
		for (int i = 0; i <= 20; ++i) {
			items.add("refresh cnt " + (++start));
		}
	}

	void findView() {
		near_listView = (XListView)  findViewById(R.id.near_listView);
		near_listView.setXListViewListener(this);
		near_listView.setOnItemClickListener(this);
	}

	void setData() {
		nearPubAdapter = new NearPubAdapter(getApplicationContext());
		nearPubAdapter.setListPageItems(items);
		if (near_listView != null && nearPubAdapter != null)
			near_listView.setAdapter(nearPubAdapter);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = new Intent(this, DetailPubActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		startActivity(intent);
	}

	@Override
	public void onRefresh() {
		if (nearPubAdapter != null) {
			items.clear();
			geneItems();
			nearPubAdapter.notifyDataSetChanged();
		}

	}

	@Override
	public void onLoadMore() {
		if (nearPubAdapter != null) {
			for (int i = 0; i <= 10; ++i) {
				items.add("refresh cnt " + (++start));
			}
			nearPubAdapter.notifyDataSetChanged();
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}


}
